package it.polimi.reTravelDream.beans;

import java.util.ArrayList;
import java.util.List;

import it.polimi.reTravelDream.dto.PrenotationDTO;
import it.polimi.reTravelDream.dto.UserDTO;
import it.polimi.reTravelDream.eao.PrenotationEAOLocal;
import it.polimi.reTravelDream.eao.UserEAOLocal;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;


@ManagedBean(name="userInfo")
@SessionScoped
public class UserInfo {
	
	@EJB
	private PrenotationEAOLocal prenotationEAOLocal;
	
	@EJB
	private UserEAOLocal userEAOLocal;
	
	private List<PrenotationDTO> allUserPrenotationDTO;
	
	private UserDTO currentUser;
	
	public UserInfo(){
		this.allUserPrenotationDTO=new ArrayList<PrenotationDTO>();
	}
	
	@PostConstruct
	public void getAllPrenotations(){
		String email=FacesContext.getCurrentInstance().getExternalContext().getRemoteUser();
		this.setCurrentUser(this.userEAOLocal.getUser(email));
		
		this.allUserPrenotationDTO=prenotationEAOLocal.getUserPrenotation(this.currentUser);
	}

	public List<PrenotationDTO> getAllUserPrenotationDTO() {
		return allUserPrenotationDTO;
	}

	public void setAllUserPrenotationDTO(List<PrenotationDTO> allUserPrenotationDTO) {
		this.allUserPrenotationDTO = allUserPrenotationDTO;
	}

	public UserDTO getCurrentUser() {
		return currentUser;
	}

	public void setCurrentUser(UserDTO currentUser) {
		this.currentUser = currentUser;
	}
}
